<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class CheckLog extends BaseModel
{
    use HasFactory;
    protected $table = 'check_log';
    // 允许批量操作的字段
    protected $fillable = ['order_id','user_id','check_time','warehouse_id','goods_shelf_id','before_num','after_num','created_at','updated_at'];

    public function scopeSearch($query,$params)
    {

        return $query;
    }

    public function order(){
        return $this->hasOne(Order::class,'id','order_id')
            ->with([
                'color',
                'product_name'=>function($q){
                    return $q->select('id','product_name');
                },
                'customer'=>function($q){
                    return $q->select('id','customer_name','customer_address','contact_phone');
                },
                'model_number_name',
                'specification'
            ])
            ->select('order.id','order.color_id','order.product_id',
                'order.customer_id','order.model_number_id','order.specification_id',
                'order.batch_number','order.remark','order.order_number');
    }

    public function stock_allocation_log(){
        return $this->hasMany(StockAllocationLog::class,'finish_product_id','id');
    }

    public function warehouse(){
        return $this->hasOne(Warehouse::class,'id','warehouse_id');
    }

    public function goods_shelf(){
        return $this->hasOne(GoodsShelf::class,'id','goods_shelf_id');
    }

}
